/*
 * @Author: Aaron Huang
 * @Date: 2022-10-31 16:02:42
 * @LastEditors: Aaron Huang
 * @LastEditTime: 2022-11-10 10:34:42
 * @Description: file content
 * @FilePath: \ias_ui\src\views\coi\CBEC\js\tableMixins.js
 * @Company: 沃尔玛
 */
import { stringToArray } from '@/utils/processingData.js'

export const tableMixins = {
  methods: {
    handleQueryParams() {
      const data = JSON.parse(JSON.stringify({ ...this.pageParams, ...this.searchData }))
      if ('itemNbrList' in data) data.itemNbrList = stringToArray(data.itemNbrList, /[\n\r]/)
      if ('skuList' in data) data.skuList = stringToArray(data.skuList, /[\n\r]/)
      if ('deptNbrList' in data) data.deptNbrList = stringToArray(data.deptNbrList, /[\n\r]/)
      // 创建时间
      if (Array.isArray(data.createByDate) && data.createByDate.length === 2) {
        data.startCreatedTime = data.createByDate[0]
        data.endCreateTime = data.createByDate[1]
      }
      // 更新时间
      if (Array.isArray(data.updateByDate) && data.updateByDate.length === 2) {
        data.startUpdatedTime = data.updateByDate[0]
        data.endUpdateTime = data.updateByDate[1]
      }
      delete data.createByDate
      delete data.updateByDate

      data.pageNum -= 1
      return data
    },
    async rePush(v) {
      try {
        this.loading = true
        const { code } = await this.rePushApi(v)
        if (code !== '0') return
        this.$message.success('重新推送成功!')
        this.handleSearch()
      } finally {
        this.loading = false
      }
    }
  }
}
